import React, { Component } from "react";
import {
  Route,
  Redirect,
  withRouter
} from "react-router-dom";
import { connect } from 'react-redux';

@connect(state=>({
  val: state.counter
}))
class PrivateRoute extends Component{
  render(){
    const { val,component: Component,location,...rest } = this.props;
    return (
      <Route
        {...rest}
        render={props =>
          val ?
          (
            <Component {...props} />
          ) :
          (
            <Redirect to="/login" />
          )
        }
      />
    )
  }
}
export default withRouter(PrivateRoute);